package cn.wolfcode.result;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class PageResult<T> {
    // 当前页
    private int currentPage = 1;
    // 每页显示的条数
    private int pageSize = 3;
    // 总记录数
    private int totalCount;
    // 每页显示的数据集合
    private List<T> list;
    // 上一页
    private int prevPage;
    // 下一页
    private int nextPage;
    // 总页数
    private int totalPage;

    public PageResult(int currentPage, int pageSize, int totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.list = data;

        this.totalPage = totalCount % pageSize ==0 ? totalCount / pageSize : totalCount / pageSize + 1 ;
        this.prevPage = currentPage - 1 >= 1 ? currentPage - 1:1;
        this.nextPage = currentPage + 1 <= this.totalPage ? currentPage + 1 : this.totalPage ;
    }
}
